home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / ACL / Examples / ACL-World / Sources / Animmasks.cp < prev    next >
Encoding:
Text File  |  1994-10-01  |  5.3 KB  |  227 lines  |  [TEXT/MMCC]

  1.  
  2. /********************************************
  3.  **** ACL-World
  4.  ****
  5.  **** Animmasks.cp
  6.  ****
  7.  **** Created:      27 August 1994
  8.  **** Modified:     29 August 1994
  9.  **** Version:      0
  10.  **** Compatible:   C++, Mac System 7
  11.  ****
  12.  **** Description:    AnimMask demo.
  13.  ****
  14.  *******************/
  15.  
  16. #include "ACL-World.h"
  17.  
  18. //*************************************
  19.  
  20.  
  21. static const short PICT_BACKGROUND     = 176;
  22. static const short PICT_PERS         = 160;
  23. static const short PICT_TREE_MASK    = 177;
  24. static const short PICT_WALL_MASK    = 179;
  25. static const short PICT_BACKGROUND2    = 180;
  26. static const short PICT_BACKGROUND3    = 181;
  27. static const short PICT_MONSTER     = 156;
  28.  
  29.  
  30.  
  31. //*************************************
  32.  
  33. #define    TEXTSTEP1    "\pExamine the background above. The charactere should be draw behind the barrier. How could it be done?"
  34.  
  35. #define    TEXTSTEP2    "\pA solution is to put a barrier object on the background barrier. But it is not a good solution because it is very slow to draw a so big object and it uses a lot of memory."
  36.  
  37. #define    TEXTSTEP3    "\pA better solution is to build an AnimMask object which has the same shape of the barrier. AnimMask objects mask all objects which are under them using a custom shape. " \
  38.  
  39.  
  40. #define    TEXTSTEP4    "\pThe sorting priority is used to know when an AnimMask is behind or in front of another Anim object. The character is masked by the AnimMask which has a higher priority than it."
  41.  
  42. #define    TEXTSTEP5    "\pNow suppose that an AnimMask is installed on the tree."
  43.  
  44. #define    TEXTSTEP6    "\pWhat happens when the charactere is in front of the tree. The priority should be modified. The tree should have a smaller priority than the charactere."
  45.  
  46. #define    TEXTSTEP7    "\pBecause AnimMasks use the sorting priority values, automatic sorting algorithms may be used to sort them. In this example, the same algorithm as the \"sorting\" demo may be used."
  47.  
  48. #define    TEXTSTEP8    "\pVisible objects and masks may be sorted with a single algorithm. Click in the picture to examine the result."
  49.  
  50.                          
  51.                     
  52. //*************************************
  53.  
  54. static AnimGfx    *background;
  55. static short    backwidth,backheight;
  56. static Anim        *anims[5];
  57.  
  58.  
  59. //*************************************
  60.  
  61. Boolean ACLWorld::animmask_advance(void)
  62. {
  63.     short     i,mw,mh;
  64.     Handle     ha;
  65.     Rect    rect;
  66.     AnimMask *mask;
  67.  
  68.     static short w,h;
  69.  
  70.     step++;
  71.     
  72.     GetDItem(dialog,1,&i,&ha,&rect);
  73.     
  74.     switch(step)
  75.     {
  76.         case 1:
  77.         SetIText(ha,TEXTSTEP1);
  78.         animbase->setsortflags(ASORT_PRIORITY);
  79.         animbase->installbackground(background);
  80.         
  81.         anims[0] = animbase->createanim(PICT_PERS);        
  82.         anims[0]->arrange_movehandlepoint(0,0,-1);
  83.         anims[0]->findmaxsize(&w,&h);
  84.         anims[0]->place((backwidth/2)-(w/2),((backheight/2)-(h/2))+h+40);
  85.         anims[0]->arrange_moveframeoffsets(0, -(w/2), 0);
  86.             
  87.         return FALSE;
  88.  
  89.         case 2:
  90.         
  91.         delete anims[0];
  92.         SetIText(ha,TEXTSTEP2);
  93.         animbase->installbackground(PICT_BACKGROUND2);            
  94.         return FALSE;
  95.  
  96.         case 3:
  97.         SetIText(ha,TEXTSTEP3);
  98.         animbase->installbackground(PICT_BACKGROUND3);            
  99.         return FALSE;
  100.  
  101.         case 4:
  102.         SetIText(ha,TEXTSTEP4);
  103.         animbase->installbackground(background);        
  104.         anims[0] = animbase->createanim(PICT_PERS);        
  105.         anims[0]->arrange_movehandlepoint(0,0,-1);
  106.         anims[0]->findmaxsize(&w,&h);
  107.         anims[0]->place((backwidth/2)-(w/2),((backheight/2)-(h/2))+h+28);
  108.         anims[0]->setpriority(-1);
  109.         anims[0]->arrange_moveframeoffsets(0, -(w/2), 0);
  110.         
  111.         mask = animbase->createanimmask(PICT_WALL_MASK);
  112.         mask->findcursize(&mw,&mh);
  113.         mask->place(-1,152+mh);
  114.         mask->setoffsety(-mh);
  115.         return FALSE;
  116.  
  117.  
  118.         case 5:
  119.         SetIText(ha,TEXTSTEP5);        
  120.         mask = animbase->createanimmask(PICT_TREE_MASK);
  121.         mask->findcursize(&mw,&mh);
  122.         mask->place(68,24+mh);
  123.         anims[0]->place(120,60+h);
  124.         mask->setoffsety(-mh);        
  125.         return FALSE;
  126.  
  127.         case 6:
  128.         SetIText(ha,TEXTSTEP6);    
  129.         anims[0]->move(0,60);
  130.         return FALSE;
  131.  
  132.         case 7:
  133.         SetIText(ha,TEXTSTEP7);
  134.         animbase->setsortflags(ASORT_BOTTOMRIGHT);        
  135.         return FALSE;
  136.  
  137.         case 8:
  138.         SetIText(ha,TEXTSTEP8);
  139.     
  140.         for(i=1;i<5;i++)
  141.         {    
  142.             anims[i] = animbase->createanim(PICT_MONSTER);
  143.             anims[i]->arrange_movehandlepoint(0,0,-1);
  144.         }
  145.     
  146.         anims[1]->place(75,145);
  147.         anims[2]->place(280,200);
  148.         anims[3]->place(78,198);
  149.         anims[4]->place(330,185);
  150.                 
  151.         return FALSE;
  152.         
  153.     }
  154.     
  155.     
  156.     return TRUE;
  157. }
  158.  
  159.  
  160.  
  161. //*************************************
  162.  
  163. Boolean ACLWorld::do_animmask(void)
  164. {
  165.     Point p;
  166.     char  key;
  167.     short res;
  168.     Boolean done = FALSE;
  169.  
  170.     pleasewait(TRUE);
  171.  
  172.     animbase = new AnimBase();
  173.     
  174.     background = animbase->newgfx(PICT_BACKGROUND);
  175.     animbase->newgfx(PICT_BACKGROUND2);
  176.     animbase->newgfx(PICT_BACKGROUND3);
  177.  
  178.     animbase->newgfx(PICT_TREE_MASK);
  179.     animbase->newgfx(PICT_WALL_MASK);
  180.  
  181.     animbase->newgfx(PICT_PERS);
  182.     animbase->newgfx(PICT_MONSTER);
  183.  
  184.  
  185.     backwidth = background->getwidth();
  186.     backheight = background->getheight();
  187.         
  188.     animbase->buildbuffer(backwidth,backheight);
  189.     animbase->setbasex(17);
  190.     animbase->setbasey(8);
  191.  
  192.  
  193.     pleasewait(FALSE);
  194.  
  195.     step = 0;
  196.     openbasedialog();
  197.     SetWTitle(dialog,"\pAnimMask");
  198.     animmask_advance();
  199.  
  200.     
  201.     for(;;)
  202.     {
  203.         res = processbasedialog(key,p);
  204.         
  205.         if         (res==DO_QUIT) {done=TRUE; break;}
  206.         else if (res==DO_MENU) break;
  207.         else if (res==DO_CONTINUE && animmask_advance()) break;
  208.         else if (res==DO_MOUSECLICK && step==8)
  209.         {
  210.             if (p.h<460 && p.v<217 && p.h>=0 && p.v>=0)
  211.             {
  212.                 if (p.v<140) p.v=140;            
  213.                 anims[0]->place(p.h,p.v);
  214.             }
  215.         }
  216.         
  217.     }
  218.     
  219.     closebasedialog();
  220.     
  221.     delete animbase;
  222.  
  223.     return done;
  224. }
  225.  
  226. //*************************************
  227.